package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.menu.MenuRemoveParam;
import top.zhangjianyong.blog.params.menu.MenuSaveOrUpdateParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.MenuService;

/**
 * 菜单Controller
 *
 * @author HDN
 * @since 2024/7/21 上午8:48
 */
@Permission(roles = {RoleKeys.ADMIN})
@RequestMapping("/menu")
@RestController
public class MenuController {

  private final MenuService menuService;

  public MenuController(MenuService menuService) {
    this.menuService = menuService;
  }

  @PostMapping("/tree/list")
  public ApiResponse treeList() {
    return menuService.treeList();
  }

  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated MenuSaveOrUpdateParam param) {
    return menuService.saveOrUpdate(param);
  }

  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated MenuRemoveParam param) {
    return menuService.remove(param);
  }
}
